import {
  Controller,
  Get,
  Req,
  Post,
  Param,
  Body,
  Res,
  HttpStatus,
  HttpException,
} from '@nestjs/common';
import { Request, Response } from 'express';
import { CreateCatDto } from './create-cat.dto';
import { CatsService } from './cats.service';
import { CatInterface } from './interfaces/cat.interface';
import { throws } from 'assert';

/**
 * 我们使用 @Controller() 装饰器定义一个基本的控制器
 * 路由路径前缀设置为 cats
 */

@Controller('cats')
export class CatsController {
  constructor(private catService: CatsService) {}

  @Post()
  async create(@Body() cat: CreateCatDto) {
    this.catService.create(cat);
  }

  @Get()
  async findAll(): Promise<CatInterface[]> {
    return this.catService.findAll();
  }

  @Get('one')
  findOne() {
    throw new HttpException('Forbidden', HttpStatus.FORBIDDEN);
  }
}
